package com.candy.control;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mail")
public class MailController {
    @Value("${spring.mail.username}")
    private String fromMail;

    @Autowired
    private JavaMailSender mailSender;

    @GetMapping("/")
    public String sendSimpleMail() throws Exception {
        SimpleMailMessage message = new SimpleMailMessage();
        System.out.println(fromMail);
        message.setFrom(fromMail);
        message.setTo("tangguo2921@163.com");
        message.setSubject("主题：测试Springboot发送邮件");
        message.setText("测试邮件内容");
        mailSender.send(message);
        return "发送成功";
    }
}
